
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<input type="button" id="btn" value="获取数据"/>
<table width="80%" align="center">
    <tr>
        <td>姓名</td>
        <td>年龄</td>
        <td>性别</td>
    </tr>
    <tbody id="content">
    </tbody>
</table>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
    $(function () {
        $("#btn").click(function () {
    $.ajax({
        dataType:"JSON",
        type:"post",
        url:"${pageContext.request.contextPath}/book/allBook",
        error:function(){
            alert('ajax请求出现错误...');
        },
        success:function (data) {
            console.log(data)
            alert(data);
            let html = "";
            for (let i = 0; i < data.length; i++) {
                html += "<tr>" +
                    "<td>" + data[i].BookID + "</td>" +
                    "<td>" + data[i].BookCounts + "</td>" +
                    "<td>" + data[i].Bookname + "</td>" +
                    "</tr>"
            }
            $("#content").html(html);
        }
    })
    })
    });
</script>




</body>
</html>
